package cn.xutongxue.interview.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.xutongxue.interview.common.ResponseResult;
import cn.xutongxue.interview.constants.UserConstant;
import cn.xutongxue.interview.entity.dto.questionBankMap.QuestionBankMapAddBatchDto;
import cn.xutongxue.interview.entity.dto.questionBankMap.QuestionBankMapRemoveBatchDto;
import cn.xutongxue.interview.enums.Errors;
import cn.xutongxue.interview.service.QuestionBankMapService;
import cn.xutongxue.interview.utils.ThrowUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 题目题库关联API
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/questionBankMap")
@Api(tags = "QuestionBankMapApi")
public class QuestionBankMapController {

    @Resource
    private QuestionBankMapService questionBankMapService;


    /**
     * 批量添加题目到题库
     *
     * @param questionBankMapAddBatchDto 待添加的题目题库关联信息
     * @return 添加结果
     */
    @ApiOperation("批量添加题目到题库")
    @PostMapping("/addBatch")
    @SaCheckRole(UserConstant.USER_ROLE_ADMIN)
    public ResponseResult<Boolean> addQuestionToBankBatch(@RequestBody QuestionBankMapAddBatchDto questionBankMapAddBatchDto) {
        ThrowUtils.throwIf(questionBankMapAddBatchDto == null, Errors.PARAMS_ERROR);
        Long bankId = questionBankMapAddBatchDto.getBankId();
        List<Long> questionIdList = questionBankMapAddBatchDto.getQuestionIdList();
        questionBankMapService.addQuestionToBankBatch(bankId, questionIdList);
        return ResponseResult.ok(true);
    }

    /**
     * 批量删除题目题库关联
     *
     * @param removeBatchDto 待删除的题目题库关联信息
     * @return 删除结果
     */
    @ApiOperation("批量删除题目题库关联")
    @PostMapping("/removeBatch")
    @SaCheckRole(UserConstant.USER_ROLE_ADMIN)
    public ResponseResult<Boolean> removeQuestionBankMapBatch(@RequestBody QuestionBankMapRemoveBatchDto removeBatchDto) {
        ThrowUtils.throwIf(removeBatchDto == null, Errors.PARAMS_ERROR);
        questionBankMapService.deleteQuestionBankMapBatch(removeBatchDto);
        return ResponseResult.ok(true);
    }
}
